{* $Id$ *}
{include file="admin/lib/header.html" title="活动管理"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">活动管理<span>{if $info}编辑{else}添加{/if}活动</span></h2>
  <a href="{AnUrl('event/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回活动列表</a>
</div>
<!--start:活动新增-->
<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('event/admin/create')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{if $event_info}{$event_info['id']}{/if}" />
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th style="width:200px;"><label for="" class="add-f-label">活动标题：</label></th>
        <td>
          <div>
            <input name="event[title]" style="width:490px;" type="text" class="add-f-ipt1" value="{$event_info.title}" placeholder="请输入活动标题" >
          </div>
        </td>
      </tr>
      <tr style="display:none;">
        <th><label for="" class="add-f-label">链接地址：</label></th>
        <td>
          <input name="event[url]" style="width:490px;" type="hidden" class="add-f-ipt1" value="{$event_info.url}" placeholder="请输入跳转的链接地址,如果不填写系统会自动生成" >
          <!-- <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入链接地址</div> -->
        </td>
      </tr>
      <tr>
        <th valign="top"><label class="add-f-label" for="">预览图片：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传图片</a>
              <input type="file" class="js_upFile" name="preview_pic">
            </div>
            <span class="tips left">&nbsp;&nbsp;&nbsp;活动图片比例：1000*500</span>
          </div>
          <div class="js_upFileBox">
              <div class="js_upFileBox">
              {if $event_info.preview_pic}
              <img src="{_image($event_info.preview_pic, 'list')}" width="270">
              {else}
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
              {/if}
          </div>
          </div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">活动内容：</label></th>
        <td>
            <script type="text/javascript">
            var ue = UE.getEditor('event_content', {
            	'initialFrameWidth'  : 800, 
            	'initialFrameHeight' : 400,
            });           
            </script>
            <!--<script id="event_content" name="event[content]" type="text/plain"></script> -->
            <textarea class="event_content" name="event[content]" id="js_editor" style="width:490px;">{$event_info.content}</textarea>
        </td>
      </tr>
      <tr>
        <th>&nbsp;</th>
        <td class="noborder">
          <button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button>
        </td>
      </tr>

    </table>
  </form>
</div>
<!--end:活动新增-->
<script>



$(function(){
	
	{if !$event_info}
	var is_send_event = false;
	{/if}
	
	$('.js_creatForm').submit(function(){
		
		{if !$event_info}
		  //判断当天是否已经发布了活动
		  $.ajax({
			  url:'{AnUrl("event/admin/is_event_send")}',
			  success : function(json){
				  if (json == 'no') {
					  showMsg('一天只能发布一条活动!');
					  is_send_event = false;
				  } else {
					  is_send_event = true;
				  }
			  }
		  });
		  
		  if (!is_send_event) {
			  return false;
		  }
		  
		{/if}
		
		//表单验证
		if(!$('input[name="event[title]"]').val() ){
			showMsg('活动标题不能为空!');
			return false;
		}

		if(!$('textarea[name="event[content]"]').val()){
			showMsg('活动内容不能为空!');
			return false;
		}
	    {if !$event_info}
	      if(!$('input[name=preview_pic]').val()){
	    	 showMsg('未上传图片!');
	    	 return false;
	      }
	    {/if}
	   
		
		
	});
	
	
	
	
	// 初始化编辑器
	  var editor = new UE.ui.Editor({
	    serverUrl:"{AnUrl('core/handler/file_uploader?source=ueditor&file_field=Filedata')}",
	       initialFrameWidth:820,
	       initialFrameHeight:450,
	       elementPathEnabled:false,
	       autoHeightEnabled: false,
	       autoFloatEnabled: false,
	       wordCount: false,
	       toolbars:[['fullscreen','source', "undo","redo","justifyleft","justifycenter","justifyright","justifyjustify","lineheight","bold","italic","underline","strikethrough","fontsize","fontfamily","backcolor","forecolor","superscript","subscript","insertorderedlist","insertunorderedlist","insertimage","inserttable","emotion","spechars","unlink","link"],[]]
	   });
	  editor.render("js_editor");
	
	// 上传图片预览
	  $(".js_upFile").each(function(i){
	    $(this).change(function(e){
	      handleFileSelect($(this), 270);
	    });
	  });
});
</script>
{include_core file="admin/lib/footer.html"}